package com.sti.platform.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aisino.core.server.BaseService;
import com.sti.platform.dao.ActDao;
import com.sti.platform.model.Busioness;
import com.sti.platform.service.ActivitiService;
import com.sti.platform.service.BusinossService;

@Service
public class BusinossServiceImpl extends BaseService implements BusinossService{
	@Autowired
	private ActDao actDao;
	@Autowired
	private ActivitiService activitiService;

	@Override
	public List<Map<String, Object>> queryStartUpBusiness(String userId) {
		List<Map<String, Object>> list = actDao.getBusiness(userId);
		for(Map<String, Object> li :list){
			String ywId = MapUtils.getString(li, "ID");
			Map<String, Object> map = actDao.getActInfoByYwId(ywId).get(0);
			String lcslId = MapUtils.getString(map, "LCSL_ID");
			
			String taskName = activitiService.queryCurrentTask(lcslId);
			List<Map<String,Object>> opinionList = this.queryOpinion(lcslId);
			if(opinionList.size()>0){
				li.put("opinion", opinionList);
			}
			if(taskName == null){
				taskName ="审核已结束";
				li.put("state", "结束");
			} else {
				li.put("state", "审核中");
			}
			li.put("taskName", taskName);
			li.put("lcslId", lcslId);
		}
		return list;
	}

	@Override
	public Busioness queryTobeAuditedTask(String lcslId) {
		Map<String,Object> map = actDao.getBusinessByLcslId(lcslId).get(0);
		String ywId = MapUtils.getString(map, "YW_ID");
		Busioness busioness = super.get(Busioness.class, ywId);
		return busioness;
	}
	
	@Override
	public List<Map<String,Object>> queryOpinion(String lcslId){
		List<Map<String,Object>> list = actDao.queryOpinion(lcslId);
		return list;
	}
	
}
